package wu.seal.utils

import com.winterbe.expekt.should
import org.junit.Before
import org.junit.Test

import java.io.File

class FileDealTest {

    val fileDeal = FileDeal()

    @Before
    fun setUp() {
    }

    @Test
    fun getMatchesNameFiles() {
        val tempFiles = listOf(File(".", "1a2b3c.cc"), File(".", "1a2b3c.log"), File(".", "1a2b3c.txt"))
        val result = fileDeal.getMatchesNameFiles(tempFiles, ".*.log")
        result.should.be.equal(listOf(File(".", "1a2b3c.log")))
        val result2 = fileDeal.getMatchesNameFiles(tempFiles, "2b")
        result2.should.be.equal(listOf(File(".", "1a2b3c.cc"), File(".", "1a2b3c.log"), File(".", "1a2b3c.txt")))
    }

    @Test
    fun getAllFilesInDir() {
        val allFilesInDir = fileDeal.getAllFilesInDir("./gradle")
        allFilesInDir.forEach {
            println(it.name)
        }
        allFilesInDir.size.should.be.equal(2)
    }

    @Test
    fun containsZip() {
        fileDeal.containsZip(File(".")).should.be.`true`
        fileDeal.containsZip(File("./build")).should.be.`false`
        fileDeal.containsZip(File("./.gradle")).should.be.`false`
    }

    @Test
    fun unzipAllFilesRecursiveAndDeleteZipedFiles() {
        val testDir = File("./testSealwu666").apply { mkdirs()}
        File("./a.zip").copyTo(File(testDir,"a.zip"))
        fileDeal.containsZip(File("./testSealwu666")).should.be.`true`
        fileDeal.unzipAllFilesRecursiveAndDeleteZipedFiles(File("./testSealwu666"))
        fileDeal.containsZip(File("./testSealwu666")).should.be.`false`
        testDir.deleteRecursively()
    }

    @Test
    fun unRarAllFilesRecursive() {
        //这个功能暂时没有启用
    }

    @Test
    fun removeAllZipFilesRecursive() {
        val testDir = File("./testSealwu666").apply { mkdirs()}
        File("./a.zip").copyTo(File(testDir,"a.zip"))
        fileDeal.containsZip(File("./testSealwu666")).should.be.`true`
        fileDeal.removeAllZipFilesRecursive(File("./testSealwu666"))
        fileDeal.containsZip(File("./testSealwu666")).should.be.`false`
        testDir.deleteRecursively()
    }

    @Test
    fun removeAllMacCacheFiles() {
    }

    @Test
    fun removeAllRarFilesRecursive() {
    }

    @Test
    fun getWorkDirTempDir() {
    }

    @Test
    fun testRegexMatch() {
        val st =
            """(19:14:35:451 |    1)      APP Tp:    1     0;  21100; WARN*****-->Warning(xrtcmain.cpp:104): Load RTC Module,Ver=70055
"""
        "AppConnectionManager".toRegex(RegexOption.IGNORE_CASE).containsMatchIn(st).should.be.`false`
    }
}